import nprogress from 'nprogress' // 进度条
import router from '@/router'
import { useToken } from '@/stores'
import 'nprogress/nprogress.css'
const whiteList = ['/login', '/404']
router.beforeEach((to, from, next) => {
  nprogress.start() // 启用进度条
  const { getToken } = useToken()
  if (getToken()) {
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})
// 后置守卫
router.afterEach(() => nprogress.done()) // 关闭进度条
